package com.chaosj.platform.wx.eventhandler;

import com.chaosj.platform.wx.runner.SpringShellRunner;
import com.github.sd4324530.fastweixin.handle.MessageHandle;
import com.github.sd4324530.fastweixin.message.BaseMsg;
import com.github.sd4324530.fastweixin.message.TextMsg;
import com.github.sd4324530.fastweixin.message.req.TextReqMsg;
import com.google.common.base.Splitter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @className: WeChatMessageHandler
 * @description:
 * @author: caoyangjie
 * @date: 2022/3/22
 **/
@Service
public class WeChatMessageHandler implements MessageHandle<TextReqMsg> {
    @Autowired
    SpringShellRunner runner;

    @Override
    public BaseMsg handle(TextReqMsg message) {
        List<String> cmds = Splitter.on(" ").omitEmptyStrings().trimResults().splitToList(message.getContent());
        String response = runner.call(cmds);
        return new TextMsg(response);
    }

    @Override
    public boolean beforeHandle(TextReqMsg message) {
        return true;
    }
}
